<div class="form full">

	<?php
	$properties = array(
		'id'=>'employee-form',
		'enableAjaxValidation'=>true,
		'htmlOptions'=>array('enctype'=>'multipart/form-data'),
	);
	$form = $this->beginWidget('CActiveForm', $properties);
	?>

	<p class="note">
		Fields with <span class="required">*</span> are required.
	</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'photo');
		echo $form->fileField($model, 'photo');
		echo $form->error($model, 'photo');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'name');
		echo $form->textField(
			$model, 'name', array('size'=>60, 'maxlength'=>128)
		);
		echo $form->error($model, 'name');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'code');
		echo $form->textField($model, 'code', array('size'=>8, 'maxlength'=>8));
		echo $form->error($model, 'code');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'gender');
		echo $form->dropDownList(
			$model, 'gender', $model->genderBehavior->list
		);
		echo $form->error($model, 'gender');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'matrimony');
		echo $form->dropDownList(
			$model, 'matrimony', $model->matrimonyBehavior->list
		);
		echo $form->error($model, 'matrimony');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'birthDate');
		$options = array(
			'model'=>$model,
			'attribute'=>'birthDate',
			'options'=>array(
				'dateFormat'=>'yy-mm-dd',
				'changeMonth'=>true,
				'changeYear'=>true,
				'yearRange'=>'1950:c+10',
			),
			'htmlOptions'=>array(
			),
		);
		$this->widget('zii.widgets.jui.CJuiDatePicker', $options);
		echo $form->error($model, 'birthDate');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'employmentDate');
		$options = array(
			'model'=>$model,
			'attribute'=>'employmentDate',
			'options'=>array(
				'dateFormat'=>'yy-mm-dd',
				'changeMonth'=>true,
				'changeYear'=>true,
			),
			'htmlOptions'=>array(
			),
		);
		$this->widget('zii.widgets.jui.CJuiDatePicker', $options);
		echo $form->error($model, 'employmentDate');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'employmentStatus');
		$contract = Employee::EMPLOYMENT_STATUS_CONTRACT;
		$permanent = Employee::EMPLOYMENT_STATUS_PERMANENT;
		$data = array(
			$contract=>$contract,
			$permanent=>$permanent,
		);
		echo $form->dropDownList($model, 'employmentStatus', $data);
		echo $form->error($model, 'employmentStatus');
		?>
	</div>

	<?php
	$style = ' style="display: block;"';
	$permanent = Employee::EMPLOYMENT_STATUS_PERMANENT;
	if (!$model->isNewRecord && $model->employmentStatus == $permanent) {
		$style = ' style="display: none;"';
	}
	?>
	<div class="row" id="expired-date-row"<?php echo $style; ?>>
		<?php
		echo $form->labelEx($model, 'expiredDate');
		$options = array(
			'model'=>$model,
			'attribute'=>'expiredDate',
			'options'=>array(
				'dateFormat'=>'yy-mm-dd',
				'changeMonth'=>true,
				'changeYear'=>true,
			),
			'htmlOptions'=>array(
			),
		);
		$this->widget('zii.widgets.jui.CJuiDatePicker', $options);
		echo $form->error($model, 'expiredDate');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'position');
		$options = array(
			'model'=>$model,
			'attribute'=>'position',
			'source'=>$model->autoCompleteData('position'),
			'htmlOptions'=>array(
				'maxlength'=>32,
			),
		);
		$this->widget('zii.widgets.jui.CJuiAutoComplete', $options);
		echo $form->error($model, 'position');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'division');
		$options = array(
			'model'=>$model,
			'attribute'=>'division',
			'source'=>$model->autoCompleteData('division'),
			'htmlOptions'=>array(
				'maxlength'=>32,
			),
		);
		$this->widget('zii.widgets.jui.CJuiAutoComplete', $options);
		echo $form->error($model, 'division');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'group');
		$options = array(
			'model'=>$model,
			'attribute'=>'group',
			'source'=>$model->autoCompleteData('group'),
			'htmlOptions'=>array(
				'maxlength'=>32,
			),
		);
		$this->widget('zii.widgets.jui.CJuiAutoComplete', $options);
		echo $form->error($model, 'group');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'supervisorId');
		$criteria = array(
			'condition'=>'isSupervisor = 1',
			'order'=>'name',
		);
		$models = $model->findAll($criteria);
		$data = CHtml::listData($models, 'id', 'name');
		$htmlOptions = array('empty'=>'');
		echo $form->dropDownList($model, 'supervisorId', $data, $htmlOptions);
		echo $form->error($model, 'supervisorId');
		?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'address');
		?>
		<?php
		echo $form->textArea($model, 'address', array('rows'=>6, 'cols'=>50));
		?>
		<?php echo $form->error($model, 'address'); ?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'email');
		?>
		<?php
		echo $form->textField($model, 'email', array('size'=>60, 'maxlength'=>128));
		?>
		<?php echo $form->error($model, 'email');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'isSupervisor');
		?>
		<?php
		echo $form->checkBox($model, 'isSupervisor');
		?>
		<?php echo $form->error($model, 'isSupervisor');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'isManagement');
		?>
		<?php
		echo $form->checkBox($model, 'isManagement');
		?>
		<?php echo $form->error($model, 'isManagement');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'workAt');
		$ho = Employee::WORK_AT_HO;
		$nonHo = Employee::WORK_AT_NON_HO;
		$data = array(
			$ho=>$ho,
			$nonHo=>$nonHo,
		);
		?>
		<table class="collapse">
			<tr>
				<td>
					<?php
					echo $form->dropDownList($model, 'workAt', $data);
					?>
				</td>
				<td>&nbsp;</td>
				<td class="full">
					<?php
					$defaults = array(
						'Airport Halim',
						'Airport Soeta',
						'Bandara',
						'Banjarmasin',
						'Medan',
						'Surabaya',
						'Tanjung Priok',
					);
					$source = $model->autoCompleteData(
						'workLocation', $defaults
					);

					$display = 'block';
					if ($model->workAt == $ho || $model->isNewRecord) {
						$display = 'none';
					}

					$options = array(
						'model'=>$model,
						'attribute'=>'workLocation',
						'source'=>$source,
						'htmlOptions'=>array(
							'style'=>"display: $display",
							'maxlength'=>32,
						),
					);
					$this->widget('zii.widgets.jui.CJuiAutoComplete', $options);
					?>
				</td>
			</tr>
		</table>
		<?php
		echo $form->error($model, 'workLocation');
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'leaveBalanceDefault');
		$htmlOptions = array('size'=>3, 'maxlength'=>2);
		echo $form->textField($model, 'leaveBalanceDefault', $htmlOptions);
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'leaveBalance');
		$htmlOptions = array('size'=>3, 'maxlength'=>2);
		echo $form->textField($model, 'leaveBalance', $htmlOptions);
		?>
	</div>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'userId');
		$criteria = array(
			'order'=>'username',
		);
		$models = User::model()->findAll($criteria);
		$data = CHtml::listData($models, 'id', 'username');
		$htmlOptions = array(
			'empty'=>''
		);
		echo $form->dropDownList($model, 'userId', $data, $htmlOptions);
		echo $form->error($model, 'userId');
		?>
	</div>

	<div class="row buttons">
		<?php
		echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save');
		?>
	</div>

	<?php $this->endWidget(); ?>

</div><!-- form -->

<?php
$cs = Yii::app()->clientScript;
$data = array(
	':employmentStatus'=>CHtml::activeId($model, 'employmentStatus'),
	':contract'=>Employee::EMPLOYMENT_STATUS_CONTRACT,
	':workAt'=>CHtml::activeId($model, 'workAt'),
	':workLocation'=>CHtml::activeId($model, 'workLocation'),
	':nonHo'=>Employee::WORK_AT_NON_HO,
);
$cs->registerScriptContent(
	'_form', 'application.views.employee._form', CClientScript::POS_READY, $data
);
?>